import time

from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By


def practice_1():
    driver = webdriver.Chrome()
    driver.get("https://www.ctrip.com/")
    # 点击机票
    driver.find_element(By.CSS_SELECTOR, ".pc_home-tabbtnIcon.lsn_ico_9C9TD").click()
    driver.find_element(By.CSS_SELECTOR, ".pc_home-jipiao.lsn_top_nav_icon_ijnym").click()
    time.sleep(2)
    # 输入伦敦
    input_dest = driver.find_element(By.CSS_SELECTOR, "[name='owACity']")
    input_dest.click()
    input_dest.send_keys(Keys.CONTROL, 'a')  #相当于ctrl A
    input_dest.send_keys("伦敦")
    time.sleep(2)
    # 点击单程
    driver.find_element(By.XPATH, "//*[text()='单程 ']").click()
    time.sleep(2)
    # 点击搜索
    driver.find_element(By.XPATH, "//*[text()='搜索']").click()
    time.sleep(2)
    #点击航班详情
    driver.find_element(By.ID, "flight-detail-link-HU7876_1724940600000GS7987_1725003900000-0").click()
    time.sleep(2)
    #断言第一个时间是否存在
    a = driver.find_element(By.CSS_SELECTOR, ".segment-header>.duration")
    assert a.text == "总时长28小时50分"


if __name__ == '__main__':
    practice_1()
